﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <WtmSearcher v-model="searchDataMachine" @search="()=>{getTableDataMachine();}">
      <el-row>
        <el-col :xs="24" :lg="6" class="mb20">
        <el-form-item ref="LineCodeId_FormItem" prop="LineCodeId" :label="$t('message.autotrans._Model_Machine_LineCode')">
            <el-select v-model="searchDataMachine.LineCodeId" clearable>
               <el-option v-for="item in stateMachine.AllLineCodes" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="6" class="mb20">
        <el-form-item ref="StationCodeId_FormItem" prop="StationCodeId" :label="$t('message.autotrans._Model_Machine_StationCode')">
            <el-select v-model="searchDataMachine.StationCodeId" clearable>
               <el-option v-for="item in stateMachine.AllStationCodes" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="6" class="mb20">
        <el-form-item ref="MachineCode_FormItem" prop="MachineCode" :label="$t('message.autotrans._Model_Machine_MachineCode')">
            <el-input v-model="searchDataMachine.MachineCode" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="6" class="mb20">
        <el-form-item ref="MachineName_FormItem" prop="MachineName" :label="$t('message.autotrans._Model_Machine_MachineName')">
            <el-input v-model="searchDataMachine.MachineName" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="6" class="mb20">
        <el-form-item ref="Asset_FormItem" prop="Asset" :label="$t('message.autotrans._Model_Machine_Asset')">
            <el-input v-model="searchDataMachine.Asset" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="6" class="mb20">
        <el-form-item ref="RatedPower_FormItem" prop="RatedPower" :label="$t('message.autotrans._Model_Machine_RatedPower')">
            <el-input v-model="searchDataMachine.RatedPower" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="6" class="mb20">
        <el-form-item ref="PersonCode_FormItem" prop="PersonCode" :label="$t('message.autotrans._Model_Machine_PersonCode')">
            <el-input v-model="searchDataMachine.PersonCode" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="6" class="mb20">
        <el-form-item ref="MachineStatus_FormItem" prop="MachineStatus" :label="$t('message.autotrans._Model_Machine_MachineStatus')">
            <el-select v-model="searchDataMachine.MachineStatus" clearable>
               <el-option key="NORMAL" value="NORMAL" :label="$t('message.autotrans._Enum_EquipmentStatus_NORMAL')"></el-option>
               <el-option key="FREE" value="FREE" :label="$t('message.autotrans._Enum_EquipmentStatus_FREE')"></el-option>
               <el-option key="MAINTAIN" value="MAINTAIN" :label="$t('message.autotrans._Enum_EquipmentStatus_MAINTAIN')"></el-option>
               <el-option key="OFFLINE" value="OFFLINE" :label="$t('message.autotrans._Enum_EquipmentStatus_OFFLINE')"></el-option>
               <el-option key="REPAIR" value="REPAIR" :label="$t('message.autotrans._Enum_EquipmentStatus_REPAIR')"></el-option>
               <el-option key="SCRAP" value="SCRAP" :label="$t('message.autotrans._Enum_EquipmentStatus_SCRAP')"></el-option>
               <el-option key="ON_MACHINE" value="ON_MACHINE" :label="$t('message.autotrans._Enum_EquipmentStatus_ON_MACHINE')"></el-option>
               <el-option key="IN_LIBRARY" value="IN_LIBRARY" :label="$t('message.autotrans._Enum_EquipmentStatus_IN_LIBRARY')"></el-option>
               <el-option key="IN_MAINTAIN" value="IN_MAINTAIN" :label="$t('message.autotrans._Enum_EquipmentStatus_IN_MAINTAIN')"></el-option>
               <el-option key="OVERHAUL" value="OVERHAUL" :label="$t('message.autotrans._Enum_EquipmentStatus_OVERHAUL')"></el-option>
               <el-option key="CH_M_AND_T" value="CH_M_AND_T" :label="$t('message.autotrans._Enum_EquipmentStatus_CH_M_AND_T')"></el-option>
               <el-option key="FAULT" value="FAULT" :label="$t('message.autotrans._Enum_EquipmentStatus_FAULT')"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
      </el-row>

  </WtmSearcher>

  <div style="text-align: right;">
      <WtmButton v-auth="'/api/BaseInformation/Machine/Create'" icon='fa fa-plus' type='primary' :button-text="$t('message.autotrans.SysCreate')" @click="OnCreateClick()"/>
    <WtmButton v-auth="'/api/BaseInformation/Machine/BatchDelete'"  icon='fa fa-trash' type='danger' :button-text="$t('message.autotrans.SysDelete')" :confirm="$t('message._system.common.vm.deletetip')" @click="onBatchDelete()"/>
    <WtmButton v-auth="'/api/BaseInformation/Machine/BatchEdit'" icon='fa fa-pencil-square' type='primary' :button-text="$t('message.autotrans.SysBatchEdit')" @click="OnBatchEditClick()"/>
    <WtmButton v-auth="'/api/BaseInformation/Machine/Import'" icon='fa fa-tasks' type='primary' :button-text="$t('message.autotrans.SysImport')" @click="OnImportClick()"/>
    <WtmButton v-auth="'/api/BaseInformation/Machine/MachineExportExcel'"  icon='fa fa-arrow-circle-down' type='primary' :button-text="$t('message.autotrans.SysExport')" @click="onExport()"/>

  </div>
  <WtmTable ref="tableRefMachine" v-bind="tableDataMachine">
    <template #operation>
      <el-table-column :label="$t('message._system.common.vm.operate')" width="180">
        <template v-slot="scope">
            <WtmButton v-auth="'/api/BaseInformation/Machine/Edit'" :is-text="true" icon='fa fa-pencil-square' type='warning' :button-text="$t('message.autotrans.SysEdit')" @click="OnEditrowClick(scope.row)"/>
          <WtmButton v-auth="'/api/BaseInformation/Machine/{id}'" :is-text="true" icon='fa fa-info-circle' type='info' :button-text="$t('message.autotrans.Page详情')" @click="OnDetailsrowClick(scope.row)"/>
          <WtmButton v-auth="'/api/BaseInformation/Machine/BatchDelete'"  icon='fa fa-trash' type='danger' :button-text="$t('message.autotrans.SysDelete')" :confirm="$t('message._system.common.vm.deletetip')" :is-text="true"  @click="onDelete(scope.row)"/>

        </template>
      </el-table-column>
    </template>
  </WtmTable>

</el-card>
</div>
</template>


<script setup lang="ts" name="message.autotrans._PageBaseInformationMachineIndex;true;TyMES.BaseInformation.Controllers;Machine">
import {  ElMessageBox, ElMessage,ElLoading } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { machineApi } from '/@/api/baseinformation/machine';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;

const CreateDialog = defineAsyncComponent(() => import('./create.vue'));
const EditDialog = defineAsyncComponent(() => import('./edit.vue'));
const DetailsDialog = defineAsyncComponent(() => import('./details.vue'));
const BatchEditDialog = defineAsyncComponent(() => import('./batchedit.vue'));
const ImportDialog = defineAsyncComponent(() => import('./import.vue'));

const stateMachine = reactive({
    
    AllLineCodes: [] as any[],
    AllStationCodes: [] as any[],
});

const searchDataMachine = ref({
        LineCodeId: null,
        StationCodeId: null,
        MachineCode: '',
        MachineName: '',
        Asset: '',
        RatedPower: null,
        PersonCode: '',
        MachineStatus: undefined,
});

// 定义变量内容
const tableRefMachine = ref();
const tableDataMachine = ref({
    // 列表数据（必传）
    data: [],
	// 表头内容（必传，注意格式）
	header: [
      {title:ci.proxy.$t('message.autotrans.Page设备产线'),key: 'Machine_LineCode',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page设备所在工位'),key: 'Machine_StationCode',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page设备编码'),key: 'Machine_MachineCode',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page设备名称'),key: 'Machine_MachineName',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page资产号'),key: 'Machine_Asset',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page额定功率'),key: 'Machine_RatedPower',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page气压'),key: 'Machine_AtmPressure',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page电压'),key: 'Machine_Voltage',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page电流'),key: 'Machine_Current',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page责任人'),key: 'Machine_PersonCode',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page设备状态'),key: 'Machine_MachineStatus',type: 'text',isCheck: true},

	],
	// 配置项（必传）
	config: {
        total: 0, // 列表总数
		loading: true, // loading 加载
		isSerialNo: true, // 是否显示表格序号
		isSelection: true, // 是否显示表格多选
		isOperate: true, // 是否显示表格操作栏
	}
});
// 初始化表格数据
const getTableDataMachine = () => {
    tableRefMachine.value.doSearch(machineApi().search, searchDataMachine.value)
        .catch((error: any) => {
			other.setFormError(ci, error);
		});
};
const OnCreateClick = () => {
    other.openDialog(ci.proxy.$t('message.autotrans.SysCreate'), CreateDialog, null, getTableDataMachine)
};

const OnEditrowClick = (row: any) => {
    other.openDialog(ci.proxy.$t('message.autotrans.SysEdit'), EditDialog, row, getTableDataMachine)
};

const OnDetailsrowClick = (row: any) => {
    other.openDialog(ci.proxy.$t('message.autotrans.Page详情'), DetailsDialog, row, getTableDataMachine)
};

// 删除
const onDelete = (row: any) => {
    machineApi().delete([row.ID]).then(() => { getTableDataMachine()})
};

const onBatchDelete = () => {
    const selectedrows = tableRefMachine.value.getSelectedRows();
    const selectedids = selectedrows.map((x: any) => x.ID);
    if (selectedids.length > 0)
      machineApi().delete(selectedids).then(() => { getTableDataMachine()})
    else
      ElMessage.error(ci.proxy.$t('message._system.common.vm.check'));
};

const OnBatchEditClick = () => {
    const selectedrows = tableRefMachine.value.getSelectedRows();
    const selectedids = selectedrows.map((x: any) => x.ID);
    if (selectedids.length > 0)
      other.openDialog(ci.proxy.$t('message.autotrans.SysBatchEdit'), BatchEditDialog, selectedids, getTableDataMachine)
    else
      ElMessage.error(ci.proxy.$t('message._system.common.vm.check'));
};

const OnImportClick = () => {
    other.openDialog(ci.proxy.$t('message.autotrans.SysImport'), ImportDialog, null, getTableDataMachine)
};

const onExport = () => {
	const selected = tableRefMachine.value.getSelectedRows();
	if (selected.length > 0) {
		machineApi().exportById(selected.map((x: any) => x.ID));
	}
	else {
		machineApi().export({});
	}
};

// 页面加载时
onMounted(() => {
    
    other.getSelectList('/api/BaseInformation/Machine/GetLines',[],false).then(x=>{stateMachine.AllLineCodes = x});
    other.getSelectList('/api/BaseInformation/Machine/GetStations',[],false).then(x=>{stateMachine.AllStationCodes = x});
        getTableDataMachine();

});

// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

